<template>
  <div>
    <div class="c-ph24 c-pb30 c-bg-white">
      <div class="c-fs30 c-pv50 c-lh c-fc-sblack c-flex-row c-justify-sb c-aligni-center">
        <span class="c-fc-xblack">反馈内容</span>
        <span class="c-fs22 c-fc-sblack" @click="linkToList">
          历史反馈 <i class="iconfont c-fs16">&#xe908;</i>
        </span>
      </div>
      <textarea v-model="content" class="needsclick c-bg-white c-fc-xblack c-w100 c-bd0 c-fs26" rows="5" placeholder="请描述您要反馈的内容">
      </textarea>
      <div class="c-textAlign-r c-fs26 c-fc-gray">{{content.length || 0}}/500</div>
    </div>
    <div class="c-hh16 c-w100 c-bg-sgray"></div>
    <div class="c-ph24 c-pb120 c-bg-white">
      <p class="c-fs30 c-pv50 c-lh c-fc-xblack">您的联系方式（非必填）</p>
      <div class=" c-bd-b1-mgray c-pb30 c-pl4">
        <input type="tel" class="c-w100 c-bd0 c-lh30 c-fs26 c-fc-xblack" v-model="contactInfo" placeholder="请填写邮箱/电话，方便我们联系您哦~">
      </div>
    </div>
    <div class="c-mh24 c-fs28 c-fc-white c-pv16 c-textAlign-c theme-bg c-br36 c-mt30 c-mb30" @click="submitForm">
      <span>提交</span>
    </div>
  </div>
</template>
<script>
import { utilJs } from "@/utils/common.js";
// let imgData = {};
// let serverIdImgArr = [];
export default {
  name: "FeedbackIndex",
  created() {
    utilJs.appShare(this);
  },
  data() {
    return {
      theme: localStorage.getItem("colorName") || "mb5_default",
      isWeixin: true,
      content: '',
      contactInfo: ''
    };
  },
  methods: {
    // 输入框失去焦点
    blurInput() {
      if (navigator.userAgent.match(/\(i[^;]+;( U;)? CPU.+Mac OS X/)) {
        setTimeout(() => {
          document.body.scrollTop = 0;
        });
      }
    },
    // 点击历史反馈
    linkToList() {
      this.$routerGo(this, "push", {
        path: '/member/feedback/feedbackList'
      })
    },
    // 提交意见反馈
    submitForm() {
      if (!this.content || (this.content && this.content.trim().length <= 0)) {
        this.$showCjToast({
          text: "请输入反馈内容",
          type: "warn",
        });
        return false;
      }
      if (this.content && this.content.length > 500) {
        this.$showCjToast({
          text: "意见反馈内容不能超过500个字",
          type: "warn",
        });
        return false;
      }
      if (this.contactInfo && !utilJs.isPhoneNumber(this.contactInfo)) {
        this.$showCjToast({
          text: "请输入正确的手机号",
          type: "warn",
        });
        return false;
      }
      if (this.btnLoading) {
        return;
      }
      this.btnLoading = true;
      var data = {
        content: this.content,
        contactInfo: this.contactInfo
      }
      var $this = this;
      utilJs.postMethod(global.apiurl + `feedback/createFeedback`, data, res => {
        $this.btnLoading = false;
        $this.$showCjToast({
          text: "提交成功！",
          type: "success",
        }).then(() => {
          $this.$routerGo($this, "replace", {
            path: "/member/menberInfo/infoIndex",
          });
        });
      }, () => {
        $this.btnLoading = false;
      })
    },
    //分享
    wechatShare: function () {
      let title = '意见反馈' || window.localStorage.getItem("shareTitle");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.wechatConfig(
        shareUrl,
        title,
        "",
        "",
        function () { },
        true
      );
    },
    //手机端分享
    appShare() {
      let title = '意见反馈' || window.localStorage.getItem("shareTitle");
      let shareUrl =
        window.location.href.split("#")[0] +
        "#" +
        this.$route.path +
        "?refereeId=" +
        localStorage.getItem("userId");
      utilJs.appShareTrue(title, "", shareUrl, "");
    }
  },
  activated() {
    setDocumentTitle("意见反馈");// eslint-disable-line
    this.content = ''
    this.contactInfo = ''
    this.isWeiXin = utilJs.isWeiXin();
    //获取阿里云签名，除了微信浏览器以外
    // if (!utilJs.isWeiXin()) {
    //   utilJs.getAliSign(`${global.apiurl}imageSign`, res => {
    //     imgData = res;
    //   });
    // }
    this.wechatShare();
  },
  deactivated() {
    this.content = ''
    this.contactInfo = ''
  }
};
</script>
<style scoped>
  textarea {
    resize: none;
  }
</style>